<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.Locale"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.ekingstar.framework.service.*"%>
<%@page import="com.ekingstar.framework.security.UserUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.ekingstar.framework.domain.Function"%>
<%@page import="com.ekingstar.framework.domain.User"%>
<%
	User user = UserUtil.getCurrentUser();
	if (user == null){
		response.sendRedirect("../user/nologin.jsp");
	}
%>
<%@ include file="/common/include.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/css.css" />
</head>
<body oncontextmenu="return false;" oncopy="return false;" onpaste="return false;" onselectstart="return false;" oncut="return false;">
<div id="top">
  <div id="top_left">
    <div id="top_right">
      <table width="90%" border="0" cellspacing="3" cellpadding="0">
        <tr>
          <td width="49%">
          	<%
			if (user != null&&user.getUserInfo()!= null&&user.getUserInfo().getName()!=null){
			%>
			<b style="color:#FFF25F"><%=user.getUserInfo().getName() %></b>&nbsp;欢迎登录本系统！ 
			<%} %>
			<br/>
             今天是
            <%
					SimpleDateFormat sf = new SimpleDateFormat("yyyy年M月d日E",Locale.CHINESE);
					out.print(sf.format(new Date()));			
			%>
		  </td>
        </tr>
      </table>
    </div>
  </div>
</div>
<div class="menu_bg">
	<div class="menu">
			<ul>
				<%
				WebApplicationContext context =  WebApplicationContextUtils.getWebApplicationContext(application);	
				IFunctionService fs = (IFunctionService) context.getBean("functionService");
				IUserService us = (IUserService) context.getBean("userService");
				String id = request.getParameter("id");
				Function parent = null;
				List subFunction = null;
				%>
				<% if (id == null || id.trim().equals("")){
					id = "-1";
				   }
					if (id.trim().equals("-1")){
					parent = new Function("-1");
					parent.setLeaf(Boolean.TRUE);
					parent.setAddresss("/welcome.jsp");
				%>
				<li class='menuvisited'>首&nbsp;&nbsp;页</li>
				<% } else {%>
					<li><a href="?id=-1"> 首&nbsp;&nbsp;页</a></li>
				<%} %>
				<%
					
					
					List functions = fs.getFunctionsByUserId(UserUtil.getCurrentUserId());
					for (int i = 0 ;functions != null && i < functions.size();i++){
						Function fun = (Function)functions.get(i);
						if (Boolean.FALSE.equals(fun.getShow())){
							continue;
						}
						if (id == null || id.trim().equals("")){
							id = fun.getId();
						}
						if (fun.getId().equals(id)){
							parent = fun;
						}
						if (fun.getId().equals(id)){
							out.print("<li class='menuvisited'>"+fun.getName()+"</li>");
						}
						else{
							out.print("<li><a href='?id="+fun.getId()+"'>"+fun.getName()+"</a></li>");
						}
					}
				%>				
			</ul>
	</div>
		
	<div class="info">
		<ul class="quit">
	      <li><a href="<%=basePath %>/user/cpwd!input.action" target="main" >修改密码</a></li>
	      <li><a href="<%=basePath %>/j_spring_security_logout" target="_top">注销</a></li>    
	    </ul>
	</div>
</div>

<% 
if (parent != null){
	session.setAttribute("parent",parent);
	subFunction=parent.getChilden();
}

%>
<script>
	//var menubar = top.frames["contents"].dtbar; 	
	//var main = top.frames["main"];
	//var fmset=window.parent.document.getElementsByTagName("frameset")["forum"];
	
	<%
	if (parent != null && Boolean.TRUE.equals(parent.getLeaf())){
		out.println("window.location='"+basePath+parent.getAddresss()+"';");
	}
	
	// if(subFunction!=null&&subFunction.size()>0){
	%>	
	   //fmset.cols="250,*";
	<%//}else{%>
	  // fmset.cols="6,*";
	<%//}%>
	
	window.location = "menu_test.jsp";
	
</script>
</body>

</html>
